package com.zut.edu.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.qmuiteam.qmui.layout.QMUIRelativeLayout;
import com.zut.edu.R;
import com.zut.edu.bean.Chart;
import com.zut.edu.widget.PieChartTool;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import lecho.lib.hellocharts.view.PieChartView;

public class StatisticsThirdFragment extends Fragment {
    @BindView(R.id.st_num)
    TextView stnum;
    @BindView(R.id.st_text)
    QMUIRelativeLayout sttext;
    @BindView(R.id.st_chart)
    QMUIRelativeLayout stchart;
    @BindView(R.id.st_pie_Chart)
    PieChartView stpieChart;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_statisticsthird,container,false);
        ButterKnife.bind(this,view);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        setLayout();
        initPieChart();
    }
    private void initPieChart(){
        List<Chart> DataList=new ArrayList<>();
        int sum=0;
        int[] num = new int[]{153,33};
        String[] lable = new String[]{"追溯成功","追溯失败"};
        for (int i = 0; i < 2; i++) {
            DataList.add(new Chart((float)num[i], lable[i]));
            sum=sum+num[i];
        }
        PieChartTool.setChartViewData(getContext(),DataList,stpieChart);
        stnum.setText("追溯成功"+num[0]+"条"+'\n'+"追溯失败"+num[1]+"条");
    }
    private void setLayout(){
        sttext.setRadius(25);
        sttext.setShadowColor(getResources().getColor(R.color.qmui_config_color_black));
        sttext.setAlpha(1.0f);
        sttext.setElevation(20);

        stchart.setRadius(25);
        stchart.setShadowColor(getResources().getColor(R.color.qmui_config_color_black));
        stchart.setAlpha(1.0f);
        stchart.setElevation(20);

    }
}
